package config

// MySQL配置项替换
func mysqlReplace(c *Config) {
	if len(c.MySQL) <= 0 {
		return
	}
	config.MySQL = nil
	for i := 0; i < len(c.MySQL); i++ {
		mysql := MySql{
			Host: "127.0.0.1",
			Port: 3306,
			User: "root",
		}
		if c.MySQL[i].Host != "" {
			mysql.Host = c.MySQL[i].Host
		}
		if c.MySQL[i].Port > 0 {
			mysql.Port = c.MySQL[i].Port
		}
		if c.MySQL[i].User != "" {
			mysql.User = c.MySQL[i].User
		}
		if c.MySQL[i].Databases != "" {
			mysql.Databases = c.MySQL[i].Databases
		}
		if c.MySQL[i].Pass != "" {
			mysql.Pass = c.MySQL[i].Pass
		}
		for j := 0; j < len(c.MySQL[i].Backups); j++ {
			back := BackupsConfig{
				ID:       "id",
				Times:    30,
				IsDelete: 2,
			}
			if c.MySQL[i].Backups[j].Table != "" {
				back.Table = c.MySQL[i].Backups[j].Table
			}
			if c.MySQL[i].Backups[j].ID != "" {
				back.ID = c.MySQL[i].Backups[j].ID
			}
			if c.MySQL[i].Backups[j].CTimes != "" {
				back.CTimes = c.MySQL[i].Backups[j].CTimes
			}
			if c.MySQL[i].Backups[j].CTimeUnix != "" {
				back.CTimeUnix = c.MySQL[i].Backups[j].CTimeUnix
			}
			if c.MySQL[i].Backups[j].Times > 0 {
				back.Times = c.MySQL[i].Backups[j].Times
			}
			if c.MySQL[i].Backups[j].IsDelete > 0 {
				back.IsDelete = c.MySQL[i].Backups[j].IsDelete
			}
			mysql.Backups = append(mysql.Backups, back)
		}
		config.MySQL = append(config.MySQL, mysql)
	}
}
